document.observe("dom:loaded", function() {
  // the element in which we will observe all clicks and capture
  // ones originating from pagination links
  var container = $(document.body)

  if (container) {
    var img = new Image
    img.src = '/images/small_shrimp_loading.gif'

    function createSpinner() {
      new Element('img', { src: img.src, 'class': 'spinner' })
    }

    container.observe('click', function(e) {
      var el = e.element()
      if (el.match('.pagination a')) {
        el.up('.pagination').insert(createSpinner())
        new Ajax.Request(el.href, { method: 'get' })
        e.stop()
      }
    })
  }
})

// function takes a table row as an argument, and based on the chosen
// authentication service, will enable/disable the password fields
function authServiceChange(selector) {
    service = selector.options[selector.selectedIndex].text
    row = selector.up('tr');
    pass_field = row.down(".password", 0);
    confirm_field = row.down(".password", 1);
    if(service == "local") {
        pass_field.disabled = false;
        confirm_field.disabled = false;
    } else {
        pass_field.disabled = true;
        confirm_field.disabled = true;
    }

}